package projectiles;

import java.awt.Dimension;
import java.awt.geom.Point2D;

import javax.swing.ImageIcon;

import core.Model;
import core.ShootingUnit;
import core.Unit;
import core.Vector;

/**
 * @author Robbie Groenewoudt
 *
 */
public abstract class Projectile extends Unit {

	protected int damage;
	protected Point2D.Double destination;
	protected int speed;
	protected Vector direction;
	protected ShootingUnit origin;
	
	public Projectile( ShootingUnit origin, Point2D.Double position, int viewAngle, Dimension size, ImageIcon image, int damage, Point2D.Double destination, int speed) {
		// Projectile heeft geen health
		super( position, 0, image, size, viewAngle );
		
		this.damage = damage;
		this.destination = destination;
		this.speed = speed;
		this.origin = origin;
		
		// Bereken direction
		// We moeten de vector normalizen of anders zit er ook een speed in
		this.direction = new Vector( destination.x - position.x, destination.y - position.y ).normalize();
		
		// Maak bounds
		calcBounds();
	}
	
	/**
	 * @return the damage
	 */
	public int getDamage() {
		return damage;
	}
	
	/**
	 * @param damage the damage to set
	 */
	public void setDamage(int damage) {
		this.damage = damage;
	}
	
	/**
	 * @return the destination
	 */
	public Point2D.Double getDestination() {
		return destination;
	}
	
	/**
	 * @param destination the destination to set
	 */
	public void setDestination(Point2D.Double destination) {
		this.destination = destination;
	}
	
	/**
	 * @return the speed
	 */
	public int getSpeed() {
		return speed;
	}
	
	/**
	 * @param speed the speed to set
	 */
	public void setSpeed(int speed) {
		this.speed = speed;
	}
	
	/**
	 * Update positie en bounds
	 * @see core.Unit#update()
	 */
	@Override
	public boolean update()
	{
		// Projectiel beweegt naar bestemming
		double deltaSpeed = this.speed * Model.timerInterval;
		setPosition( new Point2D.Double( this.position.x + ( direction.x * deltaSpeed), this.position.y + ( direction.y * deltaSpeed)  ));
		
		// Papa update bounds
		super.update();
		
		return true;
	}

	/**
	 * @return the origin
	 */
	public ShootingUnit getOrigin() {
		return origin;
	}
}